package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class DataAdvice {

    @Pointcut("execution( boolean com.itheima.service.*Service.*(..))")
    private void servicePt() {
    }

    @Around("DataAdvice.servicePt()")
    public Object trim(ProceedingJoinPoint pjp) throws Throwable {

        Object[] args = pjp.getArgs();

        for (int i = 0; i < args.length; i++) {
//            判断里面参数是不是字符串，只有字符串才能使用trim（）
            if (args[i].getClass().equals(String.class)) {
                args[i] = args[i].toString().trim();
            }
        }

        Object ret = pjp.proceed(args);

        return ret;
    }

}
